<#include "/common/easyui-css.html">
<#include "/common/easyui-js.html">
<#include "/common/loading.html">
<link rel="stylesheet" type="text/css" href="/easyui/demo.css">
<script type="text/javascript" src="/easyui/datagrid-detailview.js"></script>
<script type="text/javascript" src="/lib/layer/2.4/layer.js"></script>
<body class="easyui-layout">

<div class="easyui-panel" title="项目文档库" style="width:100%;height:100%;">
    <div class="easyui-layout" data-options="fit:true">
        <div data-options="region:'west',split:true" style="width:25%;">
                <table id="tg" class="easyui-treegrid" style="width:100%;height:100%;padding-bottom: 2px;"
                       data-options="
                    animate: true,
                    url: '/pro-document',
                    method: 'get',
                    idField: 'id',
                    treeField: 'proid',
                    onContextMenu: onContextMenu
                ">
                    <thead>
                    <tr>
                        <th data-options="field:'proid',width:180,formatter:proIdFormatter">项目生命周期</th>
                        <th data-options="field:'count',width:60,align:'center'">资料数量</th>
                    </tr>
                    </thead>
                </table>
                <div id="mm" class="easyui-menu" style="width:120px;">
                    <div onclick="detail()" data-options="iconCls:'icon-add'">详情</div>
                    <div class="menu-sep"></div>
                    <div onclick="collapse()">合闭</div>
                    <div onclick="expand()">展开</div>
                </div>
                <div id="mu" class="easyui-menu" style="width:120px;">
                    <div onclick="upload_file()" data-options="iconCls:'icon-upload'">上传</div>
                    <div class="menu-sep"></div>
                    <div onclick="collapse()">合闭</div>
                    <div onclick="expand()">展开</div>
                </div>
        </div>
        <div data-options="region:'center'" style="width:75%;">
            <div class="easyui-layout" style="width:100%;height:100%;">
                <div data-options="region:'north',split:true" style="height:40%">
                    <table id="detail_table" class="easyui-datagrid" style="width:100%;height:100%;padding-bottom: 2px;"
                           data-options="singleSelect:true,method:'get',
                                loadMsg : '数据加载中',
                                onDblClickRow:onDblClickRow">
                        <thead>
                        <tr>
                            <th data-options="field:'userId',width:100,align:'center' ,formatter:userIdFormatter">业务人员</th>
                            <th data-options="field:'proId',width:150,align:'center' ">项目编号</th>
                            <th data-options="field:'proName',width:200,align:'center' ">项目名称</th>
                            <th data-options="field:'proState',width:100,align:'center' ,formatter:proStateFormatter ">项目状态</th>
                            <th data-options="field:'proCategory',width:100,align:'center' ,formatter:proCategoryFormatter ">项目分类</th>
                        </tr>
                        </thead>
                    </table>
                </div>
                <div data-options="region:'center'" style="height:55%;">
                    <table id="document_table" class="easyui-datagrid" style="width:100%;height:100%;padding-bottom: 2px;"
                           data-options="singleSelect:true,method:'get',loadMsg : '数据加载中',
                           fitColumns:true,
                           onLoadSuccess:function(data){
                            $('.down').linkbutton({plain:true,iconCls:'icon-download'});
                        }
                        ">
                        <thead>
                            <tr>
                                <th data-options="field:'state',width:150,align:'center',formatter:docFormatter ">项目阶段</th>
                                <th data-options="field:'docType',width:150,align:'center'">文件描述</th>
                                <th data-options="field:'fileName',width:500,align:'center'">文件名称</th>
                                <th data-options="field:'id',width:500,align:'center',formatter:docDownFormatter">下载</th>
                            </tr>
                        </thead>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>

<#--<div id="dialog_upload" class="easyui-dialog" title="上传资料" data-options="closed:true,modal:true,border:'thin'" style="width: 600px; height: 150px; padding: 5px;">-->
    <#--<div style="padding: 10px">-->
        <#--<form id="form_upload" method="post" enctype="multipart/form-data" target="upload">-->
            <#--<table>-->
                <#--<tr>-->
                    <#--<td>-->
                        <#--<input type="file" name="upload" id="upload" style="width: 400px;" class="easyui-validatebox"  required="true"/>-->
                        <#--<input hidden id="id" >-->
                        <#--<input hidden id="loc" >-->
                    <#--</td>-->
                <#--</tr>-->
            <#--</table>-->
        <#--</form>-->
        <#--<iframe name="upload" style="display: none"></iframe>-->
    <#--</div>-->
    <#--<div style="text-align: right; padding: 5px;">-->
        <#--<a id="btn_upload" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)">上传</a>-->
        <#--<a id="btn_cancel" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" href="javascript:void(0)">取消</a>-->
    <#--</div>-->
<#--</div>-->

</body>
<script type="text/javascript">
    function docDownFormatter(value,row){
        var button = '';
         button += '<a href="#" class="down" title="下载" onclick=\'down('+value+')\'></a>'
        return button;
    }
    function  proCategoryFormatter(val) {
        var result = '';
        $.ajax({
            url : '/constants/proj_category/'+val,
            async : false,
            success :function (data) {
                result = data;
            }
        })
        return result;
    }
    function proStateFormatter(val) {
        var result = '';
        $.ajax({
            url : '/constants/proj_state/'+val,
            async : false,
            success :function (data) {
                result = data;
            }
        })
        return result;
    }
    function userIdFormatter(val){
        var result = '';
        $.ajax({
            url : '/user-get/'+val,
            async : false,
            success :function (data) {
                result = data;
            }
        })
        return result;
    }

    function onDblClickRow(rowIndex,rowData){
        //项目名称
        var proName = rowData.proName;
        //项目分类
        var proCategory = rowData.proCategory;
        //项目负责人
        var proManager = rowData.proManager;
        //立项时间
        var proApprovalTime = rowData.proApprovalTime;

        //项目投资对象
        var proInvestment = rowData.proInvestment;
        //项目投资时间
        var proInvestmentTime = rowData.proInvestmentTime;
        //项目投资金额
        var proInvestmentMoney = rowData.proInvestmentMoney;
        //项目股权比例
        var proProportion = rowData.proProportion;
        //项目实际投资时间
        var proRealInvestmentTime = rowData.proRealInvestmentTime;
        //项目付款时间
        var proPaymentTime = rowData.proPaymentTime;
        //项目付款金额
        var proPaymentMoney = rowData.proPaymentMoney;
        //项目投资股权比例
        var proRealProportion = rowData.proRealProportion;
        //项目合同主要条款
        var proContent = rowData.proContent;

        var info = '项目分类：'+proCategory+'<br>';
           info += '项目负责人：' + proManager + '<br>';
           info += '立项时间：' + proApprovalTime + '<br>';
           info += '项目投资对象：' + proInvestment + '<br>';
           info += '项目投资时间：' + proInvestmentTime + '<br>';
           info += '项目投资金额：' + proInvestmentMoney + '<br>';
           info += '项目股权比例：' + proProportion + '<br>';
           info += '项目实际投资时间：' + proRealInvestmentTime + '<br>';
           info += '项目付款时间：' + proPaymentTime + '<br>';
           info += '项目付款金额：' + proPaymentMoney + '<br>';
           info += '项目投资股权比例：' + proRealProportion + '<br>';
           info += '项目合同主要条款：' + proContent + '<br>';
        layer.open({
            type: 1,
            title:proName,
            area: ['420px', '240px'], //宽高
            closeBtn: 0, //不显示关闭按钮
            anim: 2,
            shadeClose: true, //开启遮罩关闭
            content: info
        });
    }
</script>
<script type="text/javascript">

    function docFormatter(value){
        var result;
        if(value=='RK'){
            result = '入库';
        }else if(value=='LX'){
            result = '立项';
        }else if(value=='JC'){
            result = '决策';
        }else if(value=='TZ'){
            result = '投资';
        }else if(value=='TH'){
            result = '投后';
        }else if(value=='TC'){
            result = '退出';
        }else if(value=='YC'){
            result = '异常';
        }else if(value == 'JJTH'){
            result = '基金投后';
        }else if(value == 'ZT'){
            result = '直投';
        }else if(value == 'FJ'){
            result = '否决';
        }
        return result;
    }

    function proIdFormatter(value,row) {
        var result = '';
        if(row.flag=='pro'){
            $.ajax({
                url: '/project-by-proid/'+value,
                async : false,
                success: function (data){
                    result = data.proName;
                }
            });

        }else if(row.flag=='lifeCycle'){
            if(value=='RK'){
                result = '入库';
            }else if(value=='LX'){
                result = '立项';
            }else if(value=='JC'){
                result = '决策';
            }else if(value=='TZ'){
                result = '投资';
            }else if(value=='TH'){
                result = '投后';
            }else if(value=='TC'){
                result = '退出';
            }else if(value=='YC'){
                result = '异常';
            }else if(value == 'JJTH'){
                result = '基金投后';
            }else if(value == 'ZT'){
                result = '直投';
            }else if(value == 'FJ'){
                result = '否决';
            }
        }else {
            result = value
        }
        return result;
    }

    function onContextMenu(e,row){
        e.preventDefault();
        $(this).treegrid('select', row.id);
        if(row.flag=='pro'){
            $('#mm').menu('show',{
                left: e.pageX,
                top: e.pageY
            });
        }else if(row.flag=='lifeCycle'){
            $('#mu').menu('show',{
                left: e.pageX,
                top: e.pageY
            });
        }


    }
    function detail(){
        var node = $('#tg').treegrid('getSelected');
        var handler = '/project-detail/'+node.proid;
        $('#detail_table').datagrid('options').url = handler;
        $('#detail_table').datagrid('reload');


        var documentHandler = '/project-document/'+node.proid;
        $('#document_table').datagrid('options').url = documentHandler;
        $('#document_table').datagrid('reload');
    }

    function upload_file(){

        var node = $('#tg').treegrid('getSelected');
        var proName = node.proid;

        var proid = 0;
        if(proName=='RK'){
            proid = 0;
        }else if(proName=='LX'){
            proid = 1;
        }else if(proName=='JC'){
            proid = 2;
        }else if(proName=='TZ'){
            proid = 3;
        }
        var id = node.upid;
        var url = '/common-upload/'+id+'/'+proid;

        var index = layer.open({
            title:'资料上传',
            type: 2,
            area: ['700px', '450px'],
            fixed: true, //不固定
            maxmin: true,
            content: url
        });
        layer.full(index);

    }
    $('#btn_upload').click(function(){
        var id = $('#id').val();
        var loc = $('#loc').val();
        $("#form_upload").form('submit', {
            type: 'post',
            url: '/upload-file/'+id+'/'+loc,
            onSubmit: function (param) {


            },
            success: function (data) {
                $('#tg').treegrid("reload",data);
                $('#dialog_upload').dialog('close');
            }
        });
    });

    $('#btn_cancel').click(function(){
        $('#dialog_upload').dialog('close');
    })

    function collapse(){
        var node = $('#tg').treegrid('getSelected');
        if (node){
            $('#tg').treegrid('collapse', node.id);
        }
    }
    function expand(){
        var node = $('#tg').treegrid('getSelected');
        if (node){
            $('#tg').treegrid('expand', node.id);
        }
    }
</script>

<script type="text/javascript">
    function down(val){
        window.location = "/project-zip?id="+val;
    }
</script>
